// 变量
const Koa = require('koa')
const app = new Koa()
const static = require('koa-static')
const fs = require('fs')
const port = 9000

// 静态文件托管
app.use(static('./dist'))

// 一律返回index.html
app.use(async ctx => {
  fs.readFile('./dist/index.html', 'utf-8', (err, content) => {
    if (err) {
      console.log('We cannot open "index.htm" file.')
    }
    ctx.body = content;
  })
})

// 监听端口
app.listen(port, () => {
  console.log('Server listening on: http://localhost:%s', port)
})